/*
 * @Description: 
 * @Author: Jinzhu Liu
 * @Date: 2021-11-27 22:53:35
 * @LastEditor: Jinzhu Liu
 * @LastEditTime: 2021-12-26 23:49:08
 */
import Admin from "../model/admin"

class AdminService {
    getAdminById(adminId: number) {
        return Admin.findByPk(adminId)
    }

    getAdminListByPage(page: number, limit: number = 10) {
        return Admin.findAndCountAll({
            limit: limit,
            offset: (page - 1) * limit
        })
    }

    getAdminByName(name: string) {
        return Admin.findOne({
            where: {
                name: name
            }
        })
    }

    addAdmin(admin: any) {
        return Admin.create(admin)
    }

    updateAdmin(id: number, admin: any) {
        return Admin.update(admin, { where: { id } })
    }

    deleteAdmin(id: number) {
        return Admin.destroy({ where: { id } })
    }
    
}

export default new AdminService